﻿
using System;
using System.Collections.Generic;

using System.Text;
using System.Collections;

namespace TdgMaker.DataType
{
    class BalisePos
    {
        public int Balise_Nr = 0;
        public int Balise_Loc = 0;
        public string Balise_Type = "";
        public string SNameTName = "";
        public int Track_Offset = 0;
        public int Up_Down = 0;
        public string Balise_Name = "";
        public ArrayList BaliseTele_List = new ArrayList();
        public int selectedTele_Index = 0;
        public string Lateral_Line = "";
        public int myPos = 0;

        public void SetBalsie_Loc(string s)
        {
            s = s.Replace(" ", "");
            s = s.Replace("K", "");
            s = s.Replace("k", "");
            s = s.Replace("+", "");
            Balise_Loc = Convert.ToInt32(s, 10);
        }

        public string getTele()
        {
            if (BaliseTele_List != null && BaliseTele_List.Count > selectedTele_Index)
            {
                return ((BaliseTele)BaliseTele_List[selectedTele_Index]).Tele;
            }
            else
            { return ""; }
        }
        public string getStationName()
        {
            string[] ss = SNameTName.Split('&');
            return ss[0];
        }

        public string getTrackName()
        {
            string[] ss = SNameTName.Split('&');
            return ss[1];
        }
        public void SetBaliseNr(string s)
        {
            //071-4-07-013-2(T1)
            string[] ss = s.Split('-', '(', ')');
            int a1 = Convert.ToInt32(ss[0], 10);
            int a2 = Convert.ToInt32(ss[1], 10);
            int a3 = Convert.ToInt32(ss[2], 10);
            int a4 = Convert.ToInt32(ss[3], 10);
            int a5 = 1;
            if (ss.Length >= 5)
            {
                a5 = Convert.ToInt32(ss[4], 10);
            }

            int aa = 0;
            aa += a5;
            aa = aa << 7;
            aa += a1;
            aa = aa << 3;
            aa += a2;
            aa = aa << 6;
            aa += a3;
            aa = aa << 8;
            aa += a4;
            this.Balise_Nr = aa;
        }

        public void getTeleFromDB()
        {
            BaliseTele_List = TB_DB.GetBaliseTele(Balise_Nr);
            selectedTele_Index = 0;
        }

        public string getBaliseNr()
        {

            string s1 = (((UInt32)Balise_Nr << 8) >> 25).ToString();
            string s2 = (((UInt32)Balise_Nr << (8 + 7)) >> 29).ToString();
            string s3 = (((UInt32)Balise_Nr << (8 + 7 + 3)) >> 26).ToString();
            string s4 = (((UInt32)Balise_Nr << (8 + 7 + 3 + 6)) >> 24).ToString();
            string s5 = (((UInt32)Balise_Nr >> 24)).ToString();

            return string.Format("{0}-{1}-{2}-{3}-{4}",s1,s2,s3,s4,s5);
            
        }

        public string getNID_BG()
        {

            string s1 = (((UInt32)Balise_Nr << 18) >> 18).ToString();
           

            return string.Format("{0}", s1);

        }
    }
}
